package com.guigu.servicegoods.controller;


import com.guigu.common_util.pojo.utils.Result;
import com.guigu.servicegoods.domain.TbStockBack;
import com.guigu.servicegoods.service.TbStockBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("/servicegoods/tbstockback")
public class TbStockBackController {

    @Autowired
    private TbStockBackService stockBackService;

    @PostMapping("fingPage")
    public Result findPage(@RequestBody(required = false) Map<String,Object> searchMap, Integer page, Integer size){
        return stockBackService.findPage(searchMap,page,size);
    }


    @PostMapping("insert")
    public Result insert(@RequestBody TbStockBack stockBack){
        if(stockBackService.save(stockBack)){
            return Result.ok();
        }
        return Result.error();
    }

    @PostMapping("update")
    public Result update(@RequestBody TbStockBack stockBack){
        if (stockBackService.updateById(stockBack)){
            return Result.ok();
        }
        return Result.error();
    }

    @GetMapping("delete")
    public Result delete(String id){
        if (stockBackService.removeById(id)){
            return Result.ok();
        }
        return Result.error();
    }

    @GetMapping("findById")
    public Result findById(String id){
        TbStockBack stockBack = stockBackService.getById(id);
        if (stockBack == null){
            return Result.error();
        }
        return Result.ok().data("stockBack",stockBack);
    }

}

